<template>
  <div class="category-sidebar modern-sidebar">
    <div class="sidebar-header">
      <h3 class="sidebar-title">
        <span class="title-text">功能分类</span>
        <span class="title-indicator"></span>
      </h3>
    </div>
    <div class="category-container">
      <ul class="category-list">
        <li 
          v-for="category in categories" 
          :key="category.id"
          class="category-item"
          :class="{ active: activeCategory === category.id }"
          @click="selectCategory(category.id)"
        >
          <span class="category-icon">{{ category.icon }}</span>
          <span class="category-name">{{ category.name }}</span>
          <span class="category-highlight"></span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useThemeStore } from '@store/theme'

// 主题状态
const themeStore = useThemeStore()
const currentTheme = computed(() => themeStore.appTheme)

// 定义props
const props = defineProps({
  initialCategory: {
    type: String,
    default: 'all'
  },
  categories: {
    type: Array,
    required: true
  }
})

// 定义emit
const emit = defineEmits(['category-change'])

// 活跃分类
const activeCategory = ref(props.initialCategory)

// 选择分类
const selectCategory = (categoryId) => {
  activeCategory.value = categoryId
  emit('category-change', categoryId)
}
</script>

<style scoped>
/* 定义现代过渡变量 */
:root {
  --modern-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --modern-hover-transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --secondary-gradient: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
}

/* 现代侧边栏容器 */
.category-sidebar.modern-sidebar {
  position: relative;
  padding: 1.5rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.05),
    0 1px 3px rgba(0, 0, 0, 0.05);
  transition: var(--modern-transition);
  overflow: hidden;
}

/* 侧边栏头部 */
.modern-sidebar .sidebar-header {
  position: relative;
  margin-bottom: 1.75rem;
}

/* 侧边栏标题 - 现代设计 */
.modern-sidebar .sidebar-title {
  position: relative;
  font-size: 1.35rem;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow: hidden;
}

/* 标题文字 */
.modern-sidebar .sidebar-title .title-text {
  position: relative;
  z-index: 2;
  color: #000000; /* 浅色主题下设置为黑色 */
  font-weight: 700;
  letter-spacing: -0.025em;
}

/* 深色主题下保留渐变效果 */
[data-theme="dark"] .modern-sidebar .sidebar-title .title-text {
  background: linear-gradient(135deg, #a5b4fc 0%, #c4b5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 标题指示器 */
.modern-sidebar .sidebar-title .title-indicator {
  width: 8px;
  height: 24px;
  background: var(--primary-gradient);
  border-radius: 4px;
  animation: pulse 2s infinite;
}

/* 标题下方装饰线 */
.modern-sidebar .sidebar-header::after {
  content: '';
  position: absolute;
  bottom: -1rem;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, 
    rgba(99, 102, 241, 0.1) 0%, 
    rgba(99, 102, 241, 0.4) 50%, 
    rgba(99, 102, 241, 0.1) 100%);
}

/* 分类容器 */
.modern-sidebar .category-container {
  position: relative;
  z-index: 1;
}

/* 分类列表 */
.modern-sidebar .category-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* 分类项 - 现代卡片式设计 */
.modern-sidebar .category-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0.875rem 1rem;
  border-radius: 14px;
  cursor: pointer;
  transition: var(--modern-hover-transition);
  font-weight: 500;
  color: #64748b;
  overflow: hidden;
  background: transparent;
  border: 1px solid transparent;
}

/* 分类高亮效果 */
.modern-sidebar .category-item .category-highlight {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--primary-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 0;
}

/* 激活状态 */
.modern-sidebar .category-item.active {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(99, 102, 241, 0.2);
  box-shadow: 
    0 6px 16px rgba(99, 102, 241, 0.12),
    0 1px 2px rgba(99, 102, 241, 0.05);
  transform: translateY(-2px);
}

.modern-sidebar .category-item.active .category-highlight {
  opacity: 0.1;
}

.modern-sidebar .category-item.active .category-name {
  color: #6366f1;
  font-weight: 600;
}

/* 悬停效果 */
.modern-sidebar .category-item:hover:not(.active) {
  background: rgba(255, 255, 255, 0.5);
  border-color: rgba(99, 102, 241, 0.1);
  transform: translateX(4px) translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.08);
}

.modern-sidebar .category-item:hover:not(.active) .category-name {
  color: #818cf8;
}

/* 分类图标 */
.modern-sidebar .category-item .category-icon {
  position: relative;
  z-index: 1;
  font-size: 1.25rem;
  margin-right: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.08);
  transition: var(--modern-hover-transition);
}

.modern-sidebar .category-item.active .category-icon {
  background: rgba(99, 102, 241, 0.15);
  transform: scale(1.05);
}

.modern-sidebar .category-item:hover .category-icon {
  transform: scale(1.1);
  background: rgba(99, 102, 241, 0.12);
}

/* 分类名称 */
.modern-sidebar .category-item .category-name {
  position: relative;
  z-index: 1;
  font-size: 0.975rem;
  transition: color 0.2s ease;
}

/* 自定义滚动条 */
.modern-sidebar::-webkit-scrollbar {
  width: 4px;
}

.modern-sidebar::-webkit-scrollbar-track {
  background: transparent;
  margin: 1rem 0;
}

.modern-sidebar::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.2);
  border-radius: 2px;
  transition: background 0.2s ease;
}

.modern-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.4);
}

/* 深色主题样式 */
[data-theme="dark"] .category-sidebar.modern-sidebar {
  background: rgba(23, 25, 35, 0.8);
  border-color: rgba(255, 255, 255, 0.05);
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.2),
    0 1px 3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .modern-sidebar .sidebar-title .title-text {
  background: linear-gradient(135deg, #a5b4fc 0%, #c4b5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

[data-theme="dark"] .modern-sidebar .sidebar-title .title-indicator {
  background: linear-gradient(135deg, #a5b4fc 0%, #c4b5fd 100%);
}

[data-theme="dark"] .modern-sidebar .sidebar-header::after {
  background: linear-gradient(90deg, 
    rgba(129, 140, 248, 0.1) 0%, 
    rgba(129, 140, 248, 0.3) 50%, 
    rgba(129, 140, 248, 0.1) 100%);
}

[data-theme="dark"] .modern-sidebar .category-item {
  color: #cbd5e1;
}

[data-theme="dark"] .modern-sidebar .category-item.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(129, 140, 248, 0.2);
  box-shadow: 
    0 6px 16px rgba(0, 0, 0, 0.2),
    0 1px 2px rgba(129, 140, 248, 0.1);
}

[data-theme="dark"] .modern-sidebar .category-item.active .category-highlight {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  opacity: 0.2;
}

[data-theme="dark"] .modern-sidebar .category-item.active .category-name {
  color: #a5b4fc;
}

[data-theme="dark"] .modern-sidebar .category-item:hover:not(.active) {
  background: rgba(100, 116, 139, 0.15);
  border-color: rgba(129, 140, 248, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .modern-sidebar .category-item:hover:not(.active) .category-name {
  color: #c7d2fe;
}

[data-theme="dark"] .modern-sidebar .category-item .category-icon {
  background: rgba(129, 140, 248, 0.12);
}

[data-theme="dark"] .modern-sidebar .category-item.active .category-icon {
  background: rgba(129, 140, 248, 0.25);
}

[data-theme="dark"] .modern-sidebar .category-item:hover .category-icon {
  background: rgba(129, 140, 248, 0.2);
}

[data-theme="dark"] .modern-sidebar::-webkit-scrollbar-thumb {
  background: rgba(129, 140, 248, 0.3);
}

[data-theme="dark"] .modern-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(129, 140, 248, 0.5);
}

[data-theme="dark"] .category-sidebar .category-item.active {
  background: rgba(99, 102, 241, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-color: rgba(129, 140, 248, 0.4);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 0 rgba(129, 140, 248, 0.3);
  color: #ffffff;
}

[data-theme="dark"] .category-sidebar .category-item:hover:not(.active) {
  background: rgba(100, 116, 139, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  color: #a5b4fc;
}

/* 动画效果 */
@keyframes pulse {
  0%, 100% {
    opacity: 0.8;
    transform: scaleY(1);
  }
  50% {
    opacity: 1;
    transform: scaleY(1.05);
  }
}

/* 加载动画 */
.modern-sidebar .category-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  transition: left 0.5s ease;
  z-index: 0;
}

.modern-sidebar .category-item:hover::before {
  left: 100%;
}

[data-theme="dark"] .modern-sidebar .category-item::before {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0) 100%
  );
}

/* 响应式设计 - 现代自适应布局 */
@media (max-width: 1200px) {
  .modern-sidebar .sidebar-title {
    font-size: 1.25rem;
  }
  
  .modern-sidebar .category-item {
    padding: 0.8rem 0.9rem;
  }
  
  .modern-sidebar .category-item .category-icon {
    font-size: 1.15rem;
    width: 28px;
    height: 28px;
  }
}

@media (max-width: 1024px) {
  .category-sidebar.modern-sidebar {
    padding: 1.25rem;
  }
  
  .modern-sidebar .sidebar-title {
    font-size: 1.15rem;
  }
  
  .modern-sidebar .sidebar-title .title-indicator {
    width: 6px;
    height: 20px;
  }
  
  .modern-sidebar .category-item {
    padding: 0.75rem 0.85rem;
  }
  
  .modern-sidebar .category-item .category-name {
    font-size: 0.9rem;
  }
}

@media (max-width: 768px) {
  .category-sidebar.modern-sidebar {
    padding: 1.1rem;
    border-radius: 16px;
  }
  
  .modern-sidebar .sidebar-header {
    margin-bottom: 1.25rem;
  }
  
  .modern-sidebar .sidebar-title {
    font-size: 1.1rem;
  }
  
  .modern-sidebar .category-container {
    overflow-x: auto;
  }
  
  .modern-sidebar .category-list {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
  }
  
  .modern-sidebar .category-item {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    white-space: nowrap;
  }
  
  .modern-sidebar .category-item .category-icon {
    font-size: 1rem;
    width: 24px;
    height: 24px;
    margin-right: 0.65rem;
  }
  
  .modern-sidebar::-webkit-scrollbar {
    height: 3px;
    width: 3px;
  }
}

@media (max-width: 480px) {
  .category-sidebar.modern-sidebar {
    padding: 1rem;
  }
  
  .modern-sidebar .sidebar-title {
    font-size: 1rem;
  }
  
  .modern-sidebar .category-list {
    gap: 0.5rem;
  }
  
  .modern-sidebar .category-item {
    padding: 0.65rem 0.85rem;
  }
  
  .modern-sidebar .category-item .category-icon {
    margin-right: 0.5rem;
  }
  
  .modern-sidebar .category-item .category-name {
    font-size: 0.85rem;
  }
}
</style>